package com.example.myandroidapp1;

import java.util.ArrayList;
import java.util.List;

import com.example.myandroidapp1.dto.GridItem;
import com.example.myandroidapp1.dto.MyGallery;
import com.example.myandroidapp1.dto.MyGalleryImage;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

public class GridViewActivity extends Activity implements OnItemClickListener {

	private GridView gridView;
	// private List<String> imageList;
	private MyGallery myGallery;

	@Override
	public void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		setContentView(R.layout.gridviewexample);
		initialize();

		gridView.setAdapter(new ImageAdapter(this, myGallery));
		gridView.setOnItemClickListener(this);

	}

	private void initialize() {
		myGallery = new MyGallery();
		// imageList = populateImageList();
		List<MyGalleryImage> myGalleryImages = populateMyGalleryImageList();
		myGallery.setImageList(myGalleryImages);

		gridView = (GridView) findViewById(R.id.gridView1);

	}

	@Override
	public void onItemClick(AdapterView<?> arg0, View v, int pos, long arg3) {
		// TODO Auto-generated method stub
		ImageView imageView = (ImageView) v.findViewById(R.id.grid_item_image);

		TextView hiddenTextView = (TextView) v.findViewById(R.id.tvGridItemHidden);
		// Toast.makeText(getApplicationContext(), hiddenTextView.getText(),
		// Toast.LENGTH_SHORT).show();

		myGallery.setCurrentPosition(pos);

		Bundle bundle = new Bundle();
		// bundle.putSerializable("gridItem", new
		// GridItem(hiddenTextView.getText().toString()));
		bundle.putSerializable("myGallery", myGallery);
		Intent i = new Intent(this, GridViewImage.class);
		i.putExtras(bundle);
		startActivity(i);

	}

	@Override
	protected void onPause() {
		super.onPause();
		finish();
	}

	/*
	 * private List<String> populateImageList() { imageList = new
	 * ArrayList<String>(); imageList.add(new MyGalleryImage(
	 * "http://166.78.125.197/mysite/web/var/ezflow_site/storage/images/gallery-1/dsc_0211/478-1-eng-US/DSC_0211_gallerythumbnail.jpg"
	 * ); imageList.add(new MyGalleryImage(
	 * "http://166.78.125.197/mysite/web/var/ezflow_site/storage/images/gallery-1/dsc_0132/482-1-eng-US/DSC_0132_gallerythumbnail.jpg"
	 * ); imageList.add(new MyGalleryImage(
	 * "http://166.78.125.197/mysite/web/var/ezflow_site/storage/images/gallery-1/dsc_0024/486-1-eng-US/DSC_0024_gallerythumbnail.jpg"
	 * ); imageList.add(new MyGalleryImage(
	 * "http://166.78.125.197/mysite/web/var/ezflow_site/storage/images/gallery-1/dsc_0941/490-1-eng-US/DSC_0941_gallerythumbnail.jpg"
	 * ); imageList.add(new MyGalleryImage(
	 * "http://166.78.125.197/mysite/web/var/ezflow_site/storage/images/gallery-1/dsc_0617/494-1-eng-US/DSC_0617_gallerythumbnail.jpg"
	 * ); imageList.add(new MyGalleryImage(
	 * "http://166.78.125.197/mysite/web/var/ezflow_site/storage/images/gallery-1/dsc_0598/498-1-eng-US/DSC_0598_gallerythumbnail.jpg"
	 * ); imageList.add(new MyGalleryImage(
	 * "http://166.78.125.197/mysite/web/var/ezflow_site/storage/images/gallery-1/dsc_0674/502-1-eng-US/DSC_0674_gallerythumbnail.jpg"
	 * ); imageList.add(new MyGalleryImage(
	 * "http://166.78.125.197/mysite/web/var/ezflow_site/storage/images/gallery-1/dsc_0524/506-1-eng-US/DSC_0524_gallerythumbnail.jpg"
	 * );
	 * 
	 * return imageList; }
	 */
	private List<MyGalleryImage> populateMyGalleryImageList() {
		
		List<MyGalleryImage> imageList = new ArrayList<MyGalleryImage>();
		imageList.add(new MyGalleryImage(
				"http://166.78.125.197/mysite/web/var/ezflow_site/storage/images/gallery-1/dsc_0211/478-1-eng-US/DSC_0211_gallerythumbnail.jpg", 0));
		imageList.add(new MyGalleryImage(
				"http://166.78.125.197/mysite/web/var/ezflow_site/storage/images/gallery-1/dsc_0132/482-1-eng-US/DSC_0132_gallerythumbnail.jpg", 1));
		imageList.add(new MyGalleryImage(
				"http://166.78.125.197/mysite/web/var/ezflow_site/storage/images/gallery-1/dsc_0024/486-1-eng-US/DSC_0024_gallerythumbnail.jpg", 2));
		imageList.add(new MyGalleryImage(
				"http://166.78.125.197/mysite/web/var/ezflow_site/storage/images/gallery-1/dsc_0941/490-1-eng-US/DSC_0941_gallerythumbnail.jpg", 3));
		imageList.add(new MyGalleryImage(
				"http://166.78.125.197/mysite/web/var/ezflow_site/storage/images/gallery-1/dsc_0617/494-1-eng-US/DSC_0617_gallerythumbnail.jpg", 4));
		imageList.add(new MyGalleryImage(
				"http://166.78.125.197/mysite/web/var/ezflow_site/storage/images/gallery-1/dsc_0598/498-1-eng-US/DSC_0598_gallerythumbnail.jpg", 5));
		imageList.add(new MyGalleryImage(
				"http://166.78.125.197/mysite/web/var/ezflow_site/storage/images/gallery-1/dsc_0674/502-1-eng-US/DSC_0674_gallerythumbnail.jpg", 6));
		imageList.add(new MyGalleryImage(
				"http://166.78.125.197/mysite/web/var/ezflow_site/storage/images/gallery-1/dsc_0524/506-1-eng-US/DSC_0524_gallerythumbnail.jpg", 7));
		return imageList;
	}

}